/**
 * Created by wangzilong on 2017/4/12.
 */

import MessageQueue from '../plugins/MessageQueue';
import ImageFetch from '../plugins/ImageFetch';

var userService = {};
// 获取群列表
userService.myGroup = function(call,access){
	var params={
		access:access,
	};
	MessageQueue('user/my-group?',params,function(msg){
		call(msg)
	})
}
// 获取群详情
userService.groupDetail = function(call,group_id,access){
	var params={
		group_id:group_id,
		access:access,
	};
	MessageQueue('user/group-detail?',params,function(msg){
		call(msg)
	})
}
// 升级群
userService.upCrowd = function(call,id,access){
	var params={
		id:id,
		access:access,
	};
	MessageQueue('user/up-crowd?',params,function(msg){
		call(msg)
	})
}
// 群成员列表
userService.groupUserQuery = function(call,group_id,access){
	var params={
		group_id:group_id,
		access:access,
	};
	MessageQueue('user/group-user-query?',params,function(msg){
		call(msg)
	})
}
// 解散群
userService.groupDismiss = function(call,group_id,access){
	var params={
		group_id:group_id,
		access:access,
	};
	MessageQueue('user/group-dismiss?',params,function(msg){
		call(msg)
	})
}
// 添加好友
userService.addFriend = function(call,friend_id,content,access){
	var params={
		friend_id:friend_id,
		content:content,
		access:access,
	};
	MessageQueue('user/add-friend?',params,function(msg){
		call(msg)
	})
}
// 设置管理员
userService.operateUsers = function(call,id,group_id,type,access){
	var params={
		id:id,
		group_id:group_id,
		type:type,
		access:access,
	};
	MessageQueue('user/operate-users?',params,function(msg){
		call(msg)
	})
}
// 获取好友列表
userService.userFriendList = function(call,is_cancel,page,access){
	var params={
		is_cancel:is_cancel,
		page:page||1,
		access:access,
	};
	MessageQueue('user/user-friend-list?',params,function(msg){
		call(msg)
	})
}
// 拉好友进群
userService.joinGroup = function(call,user_id,group_id,group_name,access){
	var params={
		user_id:user_id,
		group_id:group_id,
		group_name:group_name,
		access:access,
	};
	MessageQueue('user/join-group?',params,function(msg){
		call(msg)
	})
}
// 获取自己所有的群
userService.groupList = function(call,access){
	var params={
		access:access,
	};
	MessageQueue('user/group-list?',params,function(msg){
		call(msg)
	})
}
// 个人信息的展示
userService.userDetail = function(call,access){
	var params={
		access:access,
	};
	MessageQueue('user/user-detail?',params,function(msg){
		call(msg)
	})
}
// 修改昵称
userService.editUser = function(call,username,access){
	var params={
		username:username,
		access:access,
	};
	MessageQueue('user/edit-user?',params,function(msg){
		call(msg)
	},'POST')
}
// 修改头像
userService.userUpload = function(call,imgArr,access){
	ImageFetch('user/user-upload?',{},imgArr,access)
		.then(res=>{
			call(res)
		})
}
// 用户绑定和修改手机号
userService.bindPhone = function(call,phone,sms_code,access){
	var params={
		phone:phone,
		sms_code:sms_code,
		access:access,
	};
	MessageQueue('user/bind-phone?',params,function(msg){
		call(msg)
	},'POST')
}
// 绑定手机号
userService.saveUser = function(call,phone,password,sms_code,access){
	var params={
		phone:phone,
		password:password,
		sms_code:sms_code,
		access:access,
	};
	MessageQueue('user/save-user?',params,function(msg){
		call(msg)
	},'POST')
}

module.exports = userService;